package com.cashmama.market.api.application.controller.user;

import com.cashmama.market.api.application.controller.user.response.UserCallResponse;
import com.cashmama.market.api.application.controller.user.response.UserSmsResponse;
import com.cashmama.market.api.domain.service.SyncContactService;
import com.cashmama.market.api.domain.vo.RequestLocalInfo;
import com.cashmama.market.api.domain.vo.contact.CallVO;
import com.cashmama.market.api.domain.vo.contact.SmsVO;
import com.fqgj.common.api.DataApiResponse;
import com.fqgj.common.api.Page;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @program: market-api
 * @description
 * @author: frank
 * @create: 2019-12-25 11:40
 **/
@RestController
@RequestMapping("/syncapp")
public class SyncContactController {
    private static final Logger LOGGER = LoggerFactory.getLogger(SyncContactController.class);
    @Autowired
    private SyncContactService syncContactService;

    /**
     * 分页查询短信
     */
    @RequestMapping(value = "sms/query", method = RequestMethod.POST)
    public DataApiResponse<UserSmsResponse> getUserSmsByPage(@RequestBody Page page) {
        String userCode = RequestLocalInfo.getCurrentUser().getUserCode();
        List<SmsVO> userSmsByPage = syncContactService.getUserSmsByPage(userCode, page);
        return new DataApiResponse<>(new UserSmsResponse(userSmsByPage, page));
    }

    /**
     * 分页查询通话记录
     */
    @RequestMapping(value = "call/query", method = RequestMethod.POST)
    public DataApiResponse<UserCallResponse> getUserCallByPage(@RequestBody Page page) {
        String userCode = RequestLocalInfo.getCurrentUser().getUserCode();
        List<CallVO> callsByPage = syncContactService.getCallsByPage(userCode, page);
        return new DataApiResponse<>(new UserCallResponse(callsByPage, page));
    }
}
